//
//  DCAuthGenderCell.m
//  Demo
//
//  Created by zhaolin on 2023/1/12.
//

#import "DCAuthGenderCell.h"
#import "DCAuthInfoUIModel.h"


@interface DCAuthGenderCell ()
@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *maleBtn;

@property (nonatomic, strong) UIButton *femaleBtn;

@property (nonatomic, strong) DCAuthInfoUIModel *model;

@end
@implementation DCAuthGenderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier  {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self confiugreUI];
    }
    return self;
}

- (void)configureDataWithModel:(DCAuthInfoUIModel *)model {
    _model = model;
    _titleLabel.text = model.title;
    //男0 女1
    if(!model.content) {
        model.content = @"0";
    }
    if ([model.content isEqualToString:@"0"]) {
        _maleBtn.selected = YES;
        _femaleBtn.selected = NO;
    } else {
        _maleBtn.selected = NO;
        _femaleBtn.selected = YES;
    }
}
- (void)confiugreUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor colorWithString:@"#FFFFFF"];
    _titleLabel = [UILabel new];
    _titleLabel = [UILabel new];
    _titleLabel.text = @"title";
    _titleLabel.textColor = [UIColor colorWithString:@"#1C221B"];
    _titleLabel.font = DCFont_PF_Semibold(13);
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(24);
        make.top.mas_equalTo(15);
    }];
    
    _maleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _maleBtn.selected = YES;
    _maleBtn.titleLabel.font = DCFont_PF_Regular(13);
    [_maleBtn setTitleColor:[UIColor colorWithString:@"#131315"] forState:UIControlStateNormal];
    [_maleBtn setTitle:@"  Male" forState:UIControlStateNormal];
    [_maleBtn setImage:[UIImage imageNamed:@"icon_genderSelect"] forState:UIControlStateSelected];
    [_maleBtn setImage:[UIImage imageNamed:@"icon_genderNotSelect"] forState:UIControlStateNormal];
    [_maleBtn addTarget:self action:@selector(genderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_maleBtn];
    [_maleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(25);
        make.top.mas_equalTo(_titleLabel.mas_bottom).mas_offset(15);
        make.height.mas_equalTo(30);
    }];
    
    _femaleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _femaleBtn.selected = NO;
    _femaleBtn.titleLabel.font = DCFont_PF_Regular(13);
    [_femaleBtn setTitleColor:[UIColor colorWithString:@"#131315"] forState:UIControlStateNormal];
    [_femaleBtn setTitle:@"  Female" forState:UIControlStateNormal];
    [_femaleBtn setImage:[UIImage imageNamed:@"icon_genderSelect"] forState:UIControlStateSelected];
    [_femaleBtn setImage:[UIImage imageNamed:@"icon_genderNotSelect"] forState:UIControlStateNormal];
    [_femaleBtn addTarget:self action:@selector(genderAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_femaleBtn];
    [_femaleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_maleBtn.mas_right).mas_offset(40);
        make.top.mas_equalTo(_titleLabel.mas_bottom).mas_offset(15);
        make.height.mas_equalTo(30);
    }];
    
}

- (void)genderAction:(UIButton *)sender {
    //男0 女1
    if (sender == self.maleBtn) {
        self.maleBtn.selected = YES;
        self.femaleBtn.selected = NO;
        self.model.content = @"0";
    } else {
        self.maleBtn.selected = NO;
        self.femaleBtn.selected = YES;
        self.model.content = @"1";
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
